package de.iritgo.skillfull.component.visual;

import java.awt.Dimension;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import de.iritgo.skillfull.component.VisualComponentImpl;
import de.iritgo.skillfull.component.visitor.PositionVisitor;
import de.iritgo.skillfull.component.visitor.Visitor;
import de.iritgo.skillfull.entity.Entity;

public class ImageRenderComponentImpl extends VisualComponentImpl implements ImageRenderComponent 
{	
	
	private String imageFilename;

	private Image image;

	private PositionVisitor positionVisitor;
	
	
	public String getImageFilename ()
	{
		return imageFilename;
	}

	public void setImageFilename (String imageFilename)
	{
		this.imageFilename = imageFilename;
	}

	public void initialize ()
	{
		if (imageFilename == null)
			return;

		try
		{
			image = new Image (imageFilename);
			image.setCenterOfRotation (image.getWidth() / 2.0f * scale, image.getHeight() / 2.0f * scale);
		}
		catch (SlickException e)
		{
			e.printStackTrace();
		}
	}
	
	public void printConfiguration ()
	{
		System.out.println ("     " + toString ());
		System.out.println ("      Scale: " + scale);
	}

	public void accept (Visitor visitor)
	{
		visitor.visit (this);
	}
	
	public void setScale (float scale)
	{
		this.scale = scale;
	}

	/**
	 * @see de.iritgo.skillfull.component.VisualComponentImpl#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics, de.iritgo.skillfull.entity.Entity)
	 */
	public void render (GameContainer container, Graphics g, Entity entity)
	{
		image.setRotation (rotation);
		image.draw (x, y, scale);
	}

	public Dimension getDimension ()
	{
		return new Dimension (image.getWidth (), image.getHeight ());
	}
}	
	

